<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Barcode creation using Zend_Barcode class - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.barcode.creation.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.barcode.creation.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.barcode.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.barcode.html">Zend_Barcode</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.barcode.objects.html">Zend_Barcode Objects</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.barcode.creation" class="section"><div class="info"><h1 class="title">Barcode creation using Zend_Barcode class</h1></div>
    

    <div class="section" id="zend.barcode.creation.configuration"><div class="info"><h1 class="title">Using Zend_Barcode::factory</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Barcode</span> uses a factory method to create an instance of a
            renderer that extends <span class="classname">Zend_Barcode_Renderer_RendererAbstract</span>. The
            factory method accepts five arguments.
        </p>

        <ol type="1">
            <li class="listitem">
                <p class="para">The name of the barcode format (e.g., &quot;code39&quot;) (required)</p>
            </li>

            <li class="listitem">
                <p class="para">The name of the renderer (e.g., &quot;image&quot;) (required)</p>
            </li>

            <li class="listitem">
                <p class="para">
                    Options to pass to the barcode object (an array or
                    <span class="classname">Zend_Config</span> object) (optional)
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Options to pass to the renderer object (an array or
                    <span class="classname">Zend_Config</span> object) (optional)
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    Boolean to indicate whether or not to automatically render errors. If an
                    exception occurs, the provided barcode object will be replaced with an Error
                    representation (optional default <b><tt>TRUE</tt></b>)
                </p>
            </li>
        </ol>

        <div class="example" id="zend.barcode.creation.configuration.example-1"><div class="info"><p><b>Example #1 Getting a Renderer with Zend_Barcode::factory()</b></p></div>
            

            <div class="example-contents"><p>
                 <span class="methodname">Zend_Barcode::factory()</span> instantiates barcode objects and
                renderers and ties them together. In this first example, we will use the
                <em class="emphasis">Code39</em> barcode type together with the
                <em class="emphasis">Image</em> renderer.
            </p></div>

            <pre class="programlisting brush: php">
// Only the text to draw is required
$barcodeOptions = array(&#039;text&#039; =&gt; &#039;ZEND-FRAMEWORK&#039;);

// No required options
$rendererOptions = array();
$renderer = Zend_Barcode::factory(
    &#039;code39&#039;, &#039;image&#039;, $barcodeOptions, $rendererOptions
);
</pre>

        </div>

        <div class="example" id="zend.barcode.creation.configuration.example-2"><div class="info"><p><b>Example #2 Using Zend_Barcode::factory() with Zend_Config objects</b></p></div>
            

            <div class="example-contents"><p>
                You may pass a <span class="classname">Zend_Config</span> object to the factory in order to
                create the necessary objects. The following example is functionally equivalent to
                the previous.
            </p></div>

            <pre class="programlisting brush: php">
// Using only one Zend_Config object
$config = new Zend_Config(array(
    &#039;barcode&#039;        =&gt; &#039;code39&#039;,
    &#039;barcodeParams&#039;  =&gt; array(&#039;text&#039; =&gt; &#039;ZEND-FRAMEWORK&#039;),
    &#039;renderer&#039;       =&gt; &#039;image&#039;,
    &#039;rendererParams&#039; =&gt; array(&#039;imageType&#039; =&gt; &#039;gif&#039;),
));

$renderer = Zend_Barcode::factory($config);
</pre>

        </div>
    </div>

    <div class="section" id="zend.barcode.creation.drawing"><div class="info"><h1 class="title">Drawing a barcode</h1></div>
        

        <p class="para">
            When you <em class="emphasis">draw</em> the barcode, you retrieve the resource in which the
            barcode is drawn. To draw a barcode, you can call the  <span class="methodname">draw()</span> of
            the renderer, or simply use the proxy method provided by
            <span class="classname">Zend_Barcode</span>.
        </p>

        <div class="example" id="zend.barcode.creation.drawing.example-1"><div class="info"><p><b>Example #3 Drawing a barcode with the renderer object</b></p></div>
            

            <pre class="programlisting brush: php">
// Only the text to draw is required
$barcodeOptions = array(&#039;text&#039; =&gt; &#039;ZEND-FRAMEWORK&#039;);

// No required options
$rendererOptions = array();

// Draw the barcode in a new image,
$imageResource = Zend_Barcode::factory(
    &#039;code39&#039;, &#039;image&#039;, $barcodeOptions, $rendererOptions
)-&gt;draw();
</pre>

        </div>

        <div class="example" id="zend.barcode.creation.drawing.example-2"><div class="info"><p><b>Example #4 Drawing a barcode with Zend_Barcode::draw()</b></p></div>
            

            <pre class="programlisting brush: php">
// Only the text to draw is required
$barcodeOptions = array(&#039;text&#039; =&gt; &#039;ZEND-FRAMEWORK&#039;);

// No required options
$rendererOptions = array();

// Draw the barcode in a new image,
$imageResource = Zend_Barcode::draw(
    &#039;code39&#039;, &#039;image&#039;, $barcodeOptions, $rendererOptions
);
</pre>

        </div>
    </div>

    <div class="section" id="zend.barcode.creation.renderering"><div class="info"><h1 class="title">Renderering a barcode</h1></div>
        

        <p class="para">
            When you render a barcode, you draw the barcode, you send the headers and you send the
            resource (e.g. to a browser). To render a barcode, you can call the
             <span class="methodname">render()</span> method of the renderer or simply use the proxy method
            provided by <span class="classname">Zend_Barcode</span>.
        </p>

        <div class="example" id="zend.barcode.creation.renderering.example-1"><div class="info"><p><b>Example #5 Renderering a barcode with the renderer object</b></p></div>
            

            <pre class="programlisting brush: php">
// Only the text to draw is required
$barcodeOptions = array(&#039;text&#039; =&gt; &#039;ZEND-FRAMEWORK&#039;);

// No required options
$rendererOptions = array();

// Draw the barcode in a new image,
// send the headers and the image
Zend_Barcode::factory(
    &#039;code39&#039;, &#039;image&#039;, $barcodeOptions, $rendererOptions
)-&gt;render();
</pre>


            <div class="example-contents"><p>
                This will generate this barcode:
            </p></div>

            <div class="example-contents"><p>
                <div class="inlinemediaobject"><div class="imageobject"><img src="images/d481d625821a97b9a5eb2cec99dca50e-zend.barcode.introduction.example-1.png" alt="zend.barcode.introduction.example-1.png" width="275" height="61" /></div></div>
            </p></div>
        </div>

        <div class="example" id="zend.barcode.creation.renderering.example-2"><div class="info"><p><b>Example #6 Renderering a barcode with Zend_Barcode::render()</b></p></div>
            

            <pre class="programlisting brush: php">
// Only the text to draw is required
$barcodeOptions = array(&#039;text&#039; =&gt; &#039;ZEND-FRAMEWORK&#039;);

// No required options
$rendererOptions = array();

// Draw the barcode in a new image,
// send the headers and the image
Zend_Barcode::render(
    &#039;code39&#039;, &#039;image&#039;, $barcodeOptions, $rendererOptions
);
</pre>


            <div class="example-contents"><p>
                This will generate the same barcode as the previous example.
            </p></div>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.barcode.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.barcode.html">Zend_Barcode</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.barcode.objects.html">Zend_Barcode Objects</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.barcode.html">Zend_Barcode</a></li>
  <li><a href="zend.barcode.introduction.html">Introduction</a></li>
  <li class="active"><a href="zend.barcode.creation.html">Barcode creation using Zend_Barcode class</a></li>
  <li><a href="zend.barcode.objects.html">Zend_Barcode Objects</a></li>
  <li><a href="zend.barcode.renderers.html">Zend_Barcode Renderers</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>